/**
 * Created by Xiaoyu on 4/9/14.
 */


/**
 *  工具类
 */

var fs      = require( "fs" );
var logger  = require( 'ss-logger' ).getLogger( __filename );

/**
 * 引入modle文件
 *
 * @param model
 * @returns {Object | Boolean}
 */
function D(model){

    if(model.indexOf(".js") < 0){
        model += ".js";
    }

    var path = G.MODLE_DIR + model;

    if (fs.existsSync(path)){
        return require( path );
    } else {
        logger.error("引用Modle出错 path[ %s ]", path);
        console.trace();
        return false;
    }
}

/**
 * 引入js文件
 *
 * @param {String} staticFileName
 * @returns {Object | Boolean}
 */
function S(staticFileName){
    if(staticFileName.indexOf(".js") < 0){
        staticFileName += ".js";
    }

    var path = G.STATIC_DIR + staticFileName;

    if (fs.existsSync(path)){
        return require( path );
    } else {
        logger.error("引用静态json数据文件出错 path[ %s ]", path);
        console.trace();
        return false;
    }
}

/**
 * 引入json数据文件
 *
 * @param staticFileName
 * @returns {Object | Boolean}
 */
function J(staticFileName){
    if(staticFileName.indexOf(".json") < 0){
        staticFileName += ".json";
    }

    var path = G.STATIC_DIR + staticFileName;

    if (fs.existsSync(path)){
        return require( path );
    } else {
        logger.error("引用js数据文件出错 path[ %s ]", path);
        console.trace();
        return false;
    }

}

module.exports = {
    "D": D,
    "S": S,
    "J": J
};